package com.ailot.cloud.mall.controller;

import com.ailot.cloud.base.common.dto.Result;
import com.ailot.cloud.base.log.annotation.Oplog;
import com.ailot.cloud.mall.entity.OrderInfo;
import com.ailot.cloud.mall.service.OrderInfoService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 订单
 *
 * @Author ailot
 * @create 2025-01-13
 */

@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/orderinfo")
public class OrderInfoController {

    private final OrderInfoService orderInfoService;

    /**
     * 分页
     */
    @GetMapping("/page")
    @PreAuthorize("hasAuthority('mall:orderinfo:page')")
    public Page<OrderInfo> getOrderInfoPage(Page<OrderInfo> page, OrderInfo orderInfo) {
        return orderInfoService.page(page, Wrappers.query(orderInfo));
    }

    /**
     * 新增
     */
    @Oplog("新增")
    @PostMapping
    @PreAuthorize("hasAuthority('mall:orderinfo:add')")
    public Boolean save(@Valid @RequestBody OrderInfo orderInfo) {
        return orderInfoService.save(orderInfo);
    }

    /**
     * 修改
     */
    @Oplog("修改")
    @PutMapping
    @PreAuthorize("hasAuthority('mall:orderinfo:edit')")
    public Boolean update(@Valid @RequestBody OrderInfo orderInfo) {
        return orderInfoService.updateById(orderInfo);
    }

    /**
     * 删除
     */
    @Oplog("删除")
    @DeleteMapping("/{id}")
    @PreAuthorize("hasAuthority('mall:orderinfo:del')")
    public Result delete(@PathVariable String id) {
        return Result.success(orderInfoService.removeById(id));
    }


}